using CodeSaude.Domain.Entities;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace CodeSaude.Infrastructure.Data.EntityConfig
{
    public class BoletimDiagnosticoMap : EntityTypeConfiguration<BoletimDiagnostico>
    {
        public BoletimDiagnosticoMap()
        {
            // Primary Key
            this.HasKey(t => t.BoletimDiagnosticoId);

            // Properties
            // Table & Column Mappings
            this.ToTable("boletim_diagnostico");
            this.Property(t => t.BoletimDiagnosticoId).HasColumnName("num_sequencial");
            this.Property(t => t.id_boletim).HasColumnName("id_boletim");
            this.Property(t => t.id_diagnostico).HasColumnName("id_diagnostico");
            this.Property(t => t.id_evolucao).HasColumnName("id_evolucao");
            this.Property(t => t.id_situacao).HasColumnName("id_situacao");
            this.Property(t => t.data_criacao).HasColumnName("data_criacao");
            this.Property(t => t.Usuario_criacao).HasColumnName("Usuario_criacao");
            this.Property(t => t.data_alteracao).HasColumnName("data_alteracao");
            this.Property(t => t.Usuario_alteracao).HasColumnName("Usuario_alteracao");

            // Relationships
            this.HasRequired(t => t.boletim_atendimento)
                .WithMany(t => t.boletim_diagnostico)
                .HasForeignKey(d => d.id_boletim);

            this.HasRequired(t => t.Diagnostico)
                .WithMany(t => t.boletim_diagnostico)
                .HasForeignKey(d => d.id_diagnostico);

            this.HasOptional(t => t.evolucao)
                .WithMany(t => t.boletim_diagnostico)
                .HasForeignKey(d => d.id_evolucao);

        }
    }
}
